<?php 
class MerchandiseModel extends Model{
	public $table = "merchandise";
	public $validate = array(
		array('stock','nonull','库存名不能为空',2,3),
		array('goodsnumber','nonull','货号不能为空',2,3),
	);
	public function addData(){
	    if(!$this->create()) return FALSE;
		$attrid = implode(',', Q('post.attrid'));
		$arr = $this->getField('attrid',TRUE);
		if(in_array($attrid, $arr)){
			$this->error = "已存在货品，修改库存请编辑";
			return FALSE;
		}
		$data = array(
			'attrid' => $attrid,
			'goodsnumber' => Q('post.goodsnumber'),
			'stock' => Q('post.stock'),
			'goods_gid' => Q('post.goods_gid'),
		);
		return $this->add($data);
	}
	
}
